home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / nt_dsp2.lzh / NT_DSP2.MSA / BENCH / C-56.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-07-22  |  10.5 KB  |  344 lines

  1.         page    132,66,2,2
  2.         opt     nomd,nomex,nocex,loc,mu
  3. ;*******************************************
  4. ;Motorola Austin DSP Operation  June 30,1988
  5. ;*******************************************
  6. ;DSP56000/1
  7. ;Memory to Memory FFT - 1024 point
  8. ;File name: C-56.asm
  9. ;**************************************************************************
  10. ;    Maximum sample rate:  3.231 ms at 20.5 MHZ/ 2.453 ms at 27.0 MHz
  11. ;    Memory Size: Prog:  137 words ; Data:  6656 words
  12. ;    Number of clock cycles:    66240 (33120 instruction cycles)
  13. ;    Clock Frequency:    20.5MHz/27.0MHz
  14. ;    Instruction cycle time:    97.5ns /  74.1ns
  15. ;**************************************************************************
  16. ;
  17. ;    Updated to use faster FFT method by overlapping the butterfly
  18. ;
  19. ; Main program to verify the operation of the DSP56000 Radix 2
  20. ; complex 1024 point FFT using the
  21. ; DSP56000/1's 56 bit arithmetic, 24 bit data storage and
  22. ; 24 bit coefficient storage.
  23. ;
  24. ;       1024 point complex FFT
  25. ;       External data starts at address $400
  26. ;       Internal data starts at address 0
  27. ;       Coefficient table starts at address $800
  28. ;
  29. ;**************************************************************************
  30. ;
  31.         include 'sinegen'
  32.         include 'sincos'
  33.         include 'wbh4m'
  34.         include 'magsqr'
  35.         include 'sqrt3'
  36. ;
  37. testr2f    ident   1,0
  38.  
  39. reset   equ     0
  40. start   equ     $100
  41. points  equ     1024
  42. outdata    equ    $1000
  43. data    equ     $400
  44. coef    equ     $800
  45. window  equ     $C00
  46. mag1    equ     @pow(2.0,-8.0)
  47. mag2    equ     @pow(2.0,-8.0)
  48. ;
  49. ; Generate two tone test input.
  50. ;
  51.         org     x:data
  52.         sinegen points,mag1,0.16666,0.0
  53.         org     y:data
  54.         sinegen points,mag2,0.235,0.0
  55. ;
  56. ; Generate FFT coefficients (twiddle factors).
  57. ;
  58.         sincos  points,coef
  59. ;
  60. ; Generate Blackman-Harris 4 Term Minimum Sidelobe Window.
  61. ;
  62.         org     y:window
  63.         wbh4m  points
  64. ;
  65. ; Program starts here.
  66. ;
  67.         opt     mex
  68.         org     p:reset
  69.         jmp     start
  70.         org     p:start
  71. ;
  72. ; Window data with Blackman-Harris 4 Term Minimum Sidelobe Window.
  73. ;
  74.         move    #data,r0
  75.         move    #window,r4
  76.         move    #-1,m0               ;linear addressing
  77.         move    m0,m4
  78.         do      #points,end_wdw
  79.         move    x:(r0),x1    y:(r4)+,y0
  80.         mpyr    x1,y0,a      y:(r0),x0
  81.         mpyr    x0,y0,b      a,x:(r0)
  82.         move    b,y:(r0)+
  83. end_wdw
  84. ;
  85. ; Do 1024 point complex FFT.
  86. ;
  87.     jsr    $100
  88. ;
  89. ; Calculate magnitude of FFT.
  90. ;
  91.         move    #outdata,r0
  92.         move    #-1,m0               ;linear addressing
  93.         do      #points,end_mag
  94.         move    l:(r0),x
  95.         magsqr
  96.     move    a,l:(r0)
  97.     move    l:(r0),y
  98.         sqrt3
  99.         move    b,x:(r0)+
  100. end_mag
  101.                     ;write linear data to x memory
  102.  
  103.     nop
  104.     nop
  105.     nop
  106.     swi
  107.  
  108.     page    132,60,1,1
  109.     opt    nomd,mex
  110. fftr2fn    macro    data,coef,odata
  111. fftr2fn    ident    1,0
  112. ;
  113. ; 1024 Point Complex Fast Fourier Transform Routine
  114. ;
  115. ; This routine performs a 1024 point complex FFT on external data
  116. ; using the Radix 2, Decimation in Time, Cooley-Tukey FFT algorithm.
  117. ;
  118. ;    Complex input and output data
  119. ;        Real data in X memory
  120. ;        Imaginary data in Y memory
  121. ;    Normally ordered input data
  122. ;    Normally ordered output data
  123. ;    Coefficient lookup table
  124. ;        -Cosine values in X memory
  125. ;        -Sine values in Y memory
  126. ;
  127. ; Macro Call - fftr2fn  data,coef,odata
  128. ;
  129. ;    data       start of external data buffer
  130. ;    odata       start of external output data buffer
  131. ;    coef       start of sine/cosine table
  132. ;
  133. ; Radix 2, Decimation In Time Cooley-Tukey FFT algorithm
  134. ;             ___________
  135. ;            |           | 
  136. ; ar,ai ---->|  Radix 2  |----> ar',ai'
  137. ; br,bi ---->| Butterfly |----> br',bi'
  138. ;            |___________|
  139. ;                  ^
  140. ;                  |
  141. ;                wr,wi
  142. ;
  143. ;    ar' = ar + wr*br - wi*bi
  144. ;    ai' = ai + wi*br + wr*bi
  145. ;    br' = ar - wr*br + wi*bi = 2*ar - ar'
  146. ;    bi' = ai - wi*br - wr*bi = 2*ai - ai'
  147. ;
  148. ; Address pointers are organized as follows:
  149. ;
  150. ;    r0 = ar,ai input pointer    n0 = group offset        m0 = modulo (points)
  151. ;    r1 = br,bi input pointer    n1 = group offset        m1 = modulo (points)
  152. ;    r2 = ext. data base address    n2 = groups per pass        m2 = 256 point fft counter
  153. ;    r3 = coef. offset each pass    n3 = coefficient base address    m3 = linear
  154. ;    r4 = ar',ai' output pointer    n4 = group offset        m4 = modulo (points)
  155. ;    r5 = br',bi' output pointer    n5 = group offset        m5 = modulo (points)
  156. ;    r6 = wr,wi input pointer    n6 = coef. offset        m6 = bit reversed
  157. ;    r7 = not used (*)        n7 = output pointer storage    m7 = not used (*)
  158. ;
  159. ;    * - r7 and m7 are typically reserved for a user stack pointer.
  160. ;
  161. ; Alters Data ALU Registers
  162. ;    x1    x0    y1    y0
  163. ;    a2    a1    a0    a
  164. ;    b2    b1    b0    b
  165. ;
  166. ; Alters Address Registers
  167. ;    r0    n0    m0
  168. ;    r1    n1    m1
  169. ;    r2    n2    m2
  170. ;    r3    n3    m3
  171. ;    r4    n4    m4
  172. ;    r5    n5    m5
  173. ;    r6    n6    m6
  174. ;        n7
  175. ; Alters Program Control Registers
  176. ;    pc    sr
  177. ;
  178. ; Uses 8 locations on System Stack                                           
  179. ;
  180. ;
  181. _points    equ    1024        ;number of FFT points
  182. _intdata    equ    0        ;address of internal data workspace
  183.     move    #data,r2        ;initialize input pointers
  184.     move    r2,r0
  185.     move #_points/4,n0    ;initialize butterflies per group
  186.     move    n0,n4        ;initialize pointer offsets
  187.     move    n0,n6        ;initialize coefficient offset
  188.     move    #coef,n3        ;initialize coefficient base address
  189.     move    #_points-1,m0    ;initialize address modifiers
  190.     move    m0,m1        ;for modulo(points) addressing
  191.     move    m0,m4
  192.     move    m0,m5
  193.     move    #-1,m3        ;linear addressing for coefficient base offset
  194.     move    #0,m2        ;initialize 256 point fft counter
  195.     move    m2,m6        ;initialize coefficient address modifier
  196.                     ;for reverse carry (bit reversed) addressing
  197. ;                           
  198. ; Do first and second Radix 2 FFT passes as four-point butterflies
  199. ;
  200.     move            x:(r0)+n0,x0                ;initialize butterfly
  201.     tfr    x0,a        x:(r0)+n0,y1                ;
  202.  
  203.     do    n0,_twopass                        
  204.     tfr    y1,b        x:(r0)+n0,y0
  205.     add    y0,a        x:(r0),x1                    ;ar+cr
  206.     add    x1,b        r0,r4                    ;br+dr
  207.     add    a,b        (r0)+n0                    ;ar'=(ar+cr)+(br+dr)
  208.     subl    b,a        b,x:(r0)+n0                ;br'=(ar+cr)-(br+dr)
  209.     tfr    x0,a        a,x0            y:(r0),b
  210.     sub    y0,a                    y:(r4)+n4,y0    ;ar-cr
  211.     sub    y0,b        x0,x:(r0)                    ;bi-di
  212.     add    a,b                    y:(r0)+n0,x0    ;cr'=(ar-cr)+(bi-di)
  213.     subl    b,a        b,x:(r0)                    ;dr'=(ar-cr)-(bi-di)
  214.     tfr    x0,a        a,x0            y:(r4),b
  215.     add    y0,a                    y:(r0)+n0,y0    ;bi+di
  216.     add    y0,b        x0,x:(r0)+n0                ;ai+ci
  217.     add    b,a                    y:(r0)+,x0    ;ai'=(ai+ci)+(bi+di)
  218.     subl    a,b                    a,y:(r4)+n4    ;bi'=(ai+ci)-(bi+di)
  219.     tfr    x0,a                    b,y:(r4)+n4
  220.     sub    y0,a        x1,b                        ;ai-ci
  221.     sub    y1,b        x:(r0)+n0,x0                ;dr-br
  222.     add    a,b        x:(r0)+n0,y1                ;ci'=(ai-ci)+(dr-br)
  223.     subl    b,a                    b,y:(r4)+n4    ;di'=(ai-ci)-(dr-br)
  224.     tfr    x0,a                    a,y:(r4)+
  225. _twopass
  226. ;                                                                   
  227. ; Do remaining 8 FFT passes as four 256 point Radix 2 FFT's using internal data
  228. ; and external coefficients.
  229. ;
  230. ; Each 256 point Radix 2 FFT consists of 8 passes.  The first pass uses external
  231. ; input data and internal output data to move the data on-chip.  Intermediate
  232. ; passes use internal input data and internal output data to keep the data
  233. ; on-chip.  The last pass uses internal input data and external output data
  234. ; to move the data off-chip.
  235. ;
  236.     move #odata,r4        ;load output data address
  237.     do    #4,_end_fft    ;do 256 point fft four times
  238.     move r4,ssh        ;push output data address onto stack
  239.     move    r2,r0        ;get external data input address for first pass
  240.     move    m2,r3        ;update coefficient offset
  241.     move    #256/2,n1        ;initialize butterflies per group
  242.     move    #1,n2        ;initialize groups per pass
  243.  
  244.     do    #7,_end_pass    ;do first 7 passes out of 8
  245.     move    #_intdata,r4    ;initialize A output pointer
  246.  
  247.     move    n1,r5
  248.     move    n1,n0        ;initialize pointer offsets
  249.     lua    (r5)-,n7
  250.  
  251.     move    n1,n4
  252.     move    n1,r6
  253.     lua    (r0)+n0,r1    ;initialize B input pointer
  254.     lua    (r4)+n4,r5       ;initialize B output pointer
  255.  
  256.     lua    (r6)+,n4
  257.     move    n4,n5
  258.     lua    (r3)+n3,r6    ;initialize W input pointer
  259.     move    n4,n0
  260. ;
  261. ;    initialize butterfly
  262.     move            x:(r1),x1        y:(r6),y0        ;lookup -sine value
  263.     move                        y:(r0),b
  264.     mac    x1,y0,b    x:(r6)+n6,x0    y:(r1)+,y1
  265.     macr    -x0,y1,b                y:(r0),a         ;
  266.                 
  267.     do    n2,_end_grp
  268.                                                  
  269.     do    n7,_end_bfy
  270.     subl    b,a        x:(r0),b        b,y:(r4)
  271.     mac    -x1,x0,b    x:(r0)+,a        a,y:(r5)
  272.     macr    -y1,y0,b    x:(r1),x1
  273.     subl    b,a        b,x:(r4)+        y:(r0),b
  274.     mac    x1,y0,b                y:(r1)+,y1    ;Radix 2 DIT butterfly kernel
  275.     macr    -x0,y1,b  a,x:(r5)+        y:(r0),a        ;with constant twiddle factor
  276. _end_bfy             
  277.     move    (r1)+n1
  278.     subl    b,a        x:(r0),b        b,y:(r4)
  279.     mac    -x1,x0,b    x:(r0)+n0,a    a,y:(r5)
  280.      macr    -y1,y0,b    x:(r1),x1        y:(r6),y0      ;lookup -sine value
  281.     subl    b,a        b,x:(r4)+n4    y:(r0),b
  282.     mac    x1,y0,b    x:(r6)+n6,x0    y:(r1)+,y1
  283.     macr    -x0,y1,b    a,x:(r5)+n5    y:(r0),a        ;
  284.  
  285. _end_grp            
  286.     move    n1,b1
  287.     lsr    b    n2,a1            ;divide butterflies per group by two
  288.     lsl    a    b1,n1            ;multiply groups per pass by two
  289.     move        r3,b1    
  290.     lsr    b    a1,n2            ;divide coefficient offset by two
  291.     move        b1,r3
  292.     move        #_intdata,r0        ;intermediate passes use internal input data
  293. _end_pass
  294. ;        
  295. ; Do last FFT pass and move output data off-chip to external data memory.
  296. ;
  297.     move    n7,r1
  298.     move ssh,r4
  299.     move    (r1)+
  300.  
  301.     move    r1,n0
  302.     move    r1,n1        ;correct pointer offset for last pass
  303.     move    r1,n4
  304.     move    r1,n5
  305.  
  306.     move #_points/4,n4    ;offset for output pointer A 
  307.     lua (r0)+,r1        ;initialize B input pointer        
  308.     lua    (r4)+n4,r5    ;initialize B output pointer, first step
  309.     move n4,n5        ;offset for output pointer B 
  310.     lua    (r3)+n3,r6    ;initialize W input pointer
  311.     move (r5)+n5        ;initialize B output pointer, second step
  312.     move #0,m4        ;bit-reversed addressing for output pointer A
  313.     move m4,m5        ;bit-reversed addressing for output pointer B
  314.     move            x:(r1),x1        y:(r6),y0
  315.     move (r5)-n5        ;predecrement output pointer A
  316.     move            x:(r5),a        y:(r0),b
  317.  
  318.     do    n2,_lastpass
  319.     mac    x1,y0,b    x:(r6)+n6,x0    y:(r1)+n1,y1    ;Radix 2 DIT butterfly kernel
  320.     macr    -x0,y1,b     a,x:(r5)+n5    y:(r0),a        ;with one butterfly per group
  321.     subl    b,a        x:(r0),b    b,y:(r4)            ;and changing twiddle factor
  322.     mac    -x1,x0,b    x:(r0)+n0,a    a,y:(r5)
  323.     macr    -y1,y0,b    x:(r1),x1        y:(r6),y0
  324.     subl    b,a        b,x:(r4)+n4    y:(r0),b
  325. _lastpass
  326.     move         a,x:(r5)+n5    ;save last real result of these 256
  327.     move     m0,m4            ;reinitialize pointers for modulo addr.
  328.     move     m0,m5            ;    
  329.     move    m2,r6                ;get fft counter
  330.     move    n6,n2                ;get fft data input offset
  331.     move    m3,m2                ;external data pointer uses linear arithmetic
  332.     move    (r6)+n6                ;increment fft counter (bit reversed)
  333.     move    (r2)+n2                ;point to next 256 point fft input data
  334.     move    r6,m2                ;save fft counter
  335. _end_fft
  336.     endm
  337.  
  338.     org p:$100
  339.     fftr2fn $400,$800,$1000
  340.     rts
  341.      end
  342.     
  343. ə                                                                           
  344.